package jxerializeml;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * Contains different kind of modifiers, which might be applied on a field.
 * Purpose of this class is to make it easier to validate, for example, if
 * some field is "public", without knowing if it should be public. This
 * might happen when storing modifiers in some array and trying to compare
 * field against each of them.
 * 
 * @author Tomáš Zíma
 */
public enum FieldModifier {
	PUBLIC {
		@Override
		public boolean equals(Field field) {
			return Modifier.isPublic(field.getModifiers());
		}
	},
	PROTECTED {
		@Override
		public boolean equals(Field field) {
			return Modifier.isProtected(field.getModifiers());
		}
	},
	PRIVATE {
		@Override
		public boolean equals(Field field) {
			return Modifier.isPrivate(field.getModifiers());
		}
	},
	
	FINAL {
		@Override
		public boolean equals(Field field) {
			return Modifier.isFinal(field.getModifiers());
		}
	},
	TRANSIENT {
		@Override
		public boolean equals(Field field) {
			return Modifier.isTransient(field.getModifiers());
		}
	};
	
	/**
	 * Checks if field has some modifier (which one specifically depends
	 * on the value of this enum on which it's being called).
	 * 
	 * @param field
	 *     Checked field.
	 *   
	 * @return
	 *     True if it has the checked modifier, false if not.
	 */
	public abstract boolean equals(Field field);
}
